package com.iwinding.ladygg.ui.act;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.iwinding.ladygg.R;
import com.iwinding.ladygg.constant.SPConstant;
import com.iwinding.ladygg.utils.SPUtils;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created by hezhiyong on 2017/3/14.
 */

public class SosNoticeActivity extends BaseActivity implements View.OnClickListener {

    private final int REQUEST_CODE_FREQUENCY = 100;
    private final int REQUEST_CODE_REPEAT = 101;

    private TextView mTV_cue_frequency;
    private TextView mTV_cue_repeat;

    private int frequency_value = 1;
    private int repeat_value = 4;

    private String[] FREQUENCY_DATA = {"1","2","3","4","5"};
    private String[] REPEAT_DATA = {"0","1","2","4","8"};

    @Override
    protected int getLayoutID() {
        return R.layout.icane_activity_sos_notice;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    void initView() {
        setBackTxtResId(R.string.bottom_tab_myself);
        setTitleResId(R.string.icane_my_sos_notice);

        findViewById(R.id.lay_cue_frequency).setOnClickListener(this);
        findViewById(R.id.lay_repeat_cue).setOnClickListener(this);

        mTV_cue_frequency = (TextView) findViewById(R.id.text_cue_frequency);
        mTV_cue_repeat = (TextView) findViewById(R.id.text_repeat_cue);

        frequency_value = SPUtils.getSpPropertyInt(mContext,SPConstant.FREQUENCY,SPConstant.VALUE.FREQUENCY_VALUE);
        repeat_value = SPUtils.getSpPropertyInt(mContext,SPConstant.REPEAT,SPConstant.VALUE.REPEAT_VALUE);

        mTV_cue_frequency.setText(getString(R.string.icane_cue_frequency_value, String.valueOf(frequency_value)));
        mTV_cue_repeat.setText(getString(R.string.icane_repeat_cue_value, String.valueOf(repeat_value)));

    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this,WheelActivity.class);
        switch (v.getId()) {
            case R.id.lay_cue_frequency:
                intent.putExtra(WheelActivity.WHEELSELECTSTR,String.valueOf(frequency_value));
                intent.putStringArrayListExtra(WheelActivity.WHEELSELECTDATA, new ArrayList<String>(Arrays.asList(FREQUENCY_DATA)));
                startActivityForResult(intent,REQUEST_CODE_FREQUENCY);
                break;
            case R.id.lay_repeat_cue:
                intent.putExtra(WheelActivity.WHEELSELECTSTR,String.valueOf(repeat_value));
                intent.putStringArrayListExtra(WheelActivity.WHEELSELECTDATA, new ArrayList<String>(Arrays.asList(REPEAT_DATA)));
                startActivityForResult(intent,REQUEST_CODE_REPEAT);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode==RESULT_OK){
            String str = data.getStringExtra(WheelActivity.WHEELSELECTSTR);
            switch (requestCode){
                case REQUEST_CODE_FREQUENCY:
                    frequency_value = Integer.parseInt(str);
                    mTV_cue_frequency.setText(getString(R.string.icane_cue_frequency_value, String.valueOf(frequency_value)));
                    SPUtils.putSpProperty(mContext, SPConstant.FREQUENCY,frequency_value);
                    break;
                case REQUEST_CODE_REPEAT:
                    repeat_value = Integer.parseInt(str);
                    mTV_cue_repeat.setText(getString(R.string.icane_repeat_cue_value, String.valueOf(repeat_value)));
                    SPUtils.putSpProperty(mContext, SPConstant.REPEAT,repeat_value);
                    break;

            }
        }
    }
}
